package com.example.mybatis_plus_use.dto;

import com.example.mybatis_plus_use.ValidationGroups.ValidationGroups.UpdateGroup;
import com.example.mybatis_plus_use.ValidationGroups.ValidationGroups.RegisterGroup;
import com.example.mybatis_plus_use.ValidationGroups.ValidationGroups.LoginGroup;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public class UserLogindto {
    @NotBlank(message = "用户名不能为空", groups = {RegisterGroup.class})
    @Size(min = 2, max = 20, message = "用户名长度必须在2-20之间", groups = {LoginGroup.class})
    private String username;

    @NotBlank(message = "密码不能为空", groups =  LoginGroup.class)
    @Pattern(
            regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$",
            message = "密码必须包含大小写字母和数字，长度至少8位",
            groups =   RegisterGroup.class)
    private String password;

    public @NotBlank(message = "用户名不能为空", groups = {RegisterGroup.class}) @Size(min = 2, max = 20, message = "用户名长度必须在2-20之间",
            groups = {RegisterGroup.class, UpdateGroup.class}) String getUsername() {
        return username;
    }

    public void setUsername(@NotBlank(message = "用户名不能为空", groups = {RegisterGroup.class}) @Size(min = 2, max = 20, message = "用户名长度必须在2-20之间",
            groups = {RegisterGroup.class, UpdateGroup.class}) String username) {
        this.username = username;
    }

    public @NotBlank(message = "密码不能为空", groups = RegisterGroup.class) @Pattern(
            regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$",
            message = "密码必须包含大小写字母和数字，长度至少8位",
            groups = RegisterGroup.class) String getPassword() {
        return password;
    }

    public void setPassword(@NotBlank(message = "密码不能为空", groups = RegisterGroup.class) @Pattern(
            regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$",
            message = "密码必须包含大小写字母和数字，长度至少8位",
            groups = RegisterGroup.class) String password) {
        this.password = password;
    }
}
